package com.hongdee.crm.question.service.Impl;

import com.hongdee.common.util.TokenUtil;
import com.hongdee.crm.question.dao.ITCrmQuestionGroupItemDao;
import com.hongdee.crm.question.service.ITCrmQuestionGroupItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Name: 问卷管理 问题项管理
 * @Author: Liu XiaoLong
 * @Date: 2017/10/16 10:47
 * @Remark:
 */
@Service
public class TCrmQuestionGroupItemServiceImpl implements ITCrmQuestionGroupItemService{
    @Autowired
    private ITCrmQuestionGroupItemDao itCrmQuestionGroupItemDao;
    private String tableName = "T_CRM_SURVERY_QUESTION_GROUP_ITEM";

    /**
     * @Name: 分页查询
     * @Author: Liu XiaoLong
     * @Date: 2017/10/16 10:52
     * @Remark:
     */
    @Override
    public Map page(String uid,Map data,String start,String limit) throws Exception {
        String companyId = TokenUtil.getCompanyId(uid);
        String sql = "SELECT a.id,a.group_id,a.item_id,a.company_id,a.score,b.item_code,b.item_name,b.item_type,b.group_code,b.disp_order " +
                "FROM t_crm_survery_question_group_item a LEFT JOIN t_crm_survery_item b ON a.item_id = b.id WHERE a.company_id = ? ";
        List params = new ArrayList();
        params.add(companyId);
        if(!data.get("questionId").toString().isEmpty()){
            sql += "AND a.quesiton_id = ? ";
            params.add(data.get("questionId").toString());
        }
        if(!data.get("groupId").toString().isEmpty()){
            sql += "AND a.group_id = ? ";
            params.add(data.get("groupId").toString());
        }
        return itCrmQuestionGroupItemDao.page(sql,params.toArray(),start,limit);
    }
}
